<template>
  <div>
    <el-card>
      <div class="ding">
        学生姓名:<el-input v-model="input" placeholder="请输入内容" clearable @input="search" @clear="clear" />
      </div>
      <el-table
        :data="juantable"
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          width="130px"
        />
        <el-table-column
          label="姓名"
          prop="name"
        />
        <el-table-column
          label="试卷名称"
        >
          <template slot-scope="scope">
            {{ scope.row.testinfo.sjname }}
          </template>
        </el-table-column>
        <el-table-column
          label="试卷总分"
        >
          <template slot-scope="scope">
            {{ scope.row.testinfo.tscore }}
          </template>
        </el-table-column>
        <el-table-column
          label="试卷得分"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.tscore==-1">未审批</span>
            <span v-else class="red">{{ scope.row.tscore }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" width="200px">
          <template slot-scope="scope">
            <el-button v-if="scope.row.tscore==-1" @click="pan(scope.row)"><a class="blue">判卷</a></el-button>
            <el-button v-else disabled @click="pan(scope.row)"><a class="qblue">判卷</a></el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        :page-sizes="[5, 10, 15, 20]"
        :page-size="5"
        layout="total, sizes, prev, pager, next, jumper"
        :total="t"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      juantable: [],
      size: 5,
      page: 1,
      t: 0,
      pageisornot: false,
      input: '',
      role: ''
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getjuan()
    // this.role=sessionStorage.getItem("user")
  },
  mounted() {},
  methods: {
    async getjuan() {
      this.pageisornot = false
      var res = await this.http.get('/test/kao/', {
        params: {
          page: this.page,
          size: this.size
        }
      })
      console.log(res)
      if (res.data.code == 200) {
        this.juantable = res.data.data
        this.t = res.data.total
      }
    },
    add() {
      this.$router.push('/kaotiadd')
    },
    async search() {
      if (!this.pageisornot) {
        this.page = 1
      }
      if (this.input != '') {
        var res = await this.http.get('/test/kao/', {
          params: { name: this.input, page: this.page,
            size: this.size }
        })
        if (res.data.code == 200) {
          this.juantable = res.data.data
        }
      } else {
        this.getjuan()
      }
      this.pageisornot = true
    },
    clear() {
      this.gettest()
    },
    handleSizeChange(v) {
      this.size = v
      if (this.pageisornot) {
        this.search()
      } else {
        this.getjuan()
      }
    },
    handleCurrentChange(v) {
      this.page = v
      if (this.pageisornot) {
        this.search()
      } else {
        this.getjuan()
      }
    },
    pan(row) {
      this.$router.push({ path: '/pan', query: { id: row.id }})
    }
  }
}
</script>
<style scoped>
    .el-input{
        width: 200px;
        margin-left: 7px;
    }
    .el-pagination{
      margin-top: 20px;
      text-align: center;
    }
    .ding .el-button{
        float: right;
    }
    .el-table .el-button{
      background: 0;
      padding-left: 0;
      padding-right: 0;
      display: inline-block;
      border:0;
    }
    .blue{
      color: #3175fb;
    }
    .qblue{
      color: #B0C4DE;
    }
    .red{
        color: red;
    }
</style>
